import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    /*游戏得分*/
    score: 0,
    /*记录游戏状态，0初始，1胜利，2输*/
    winning: 0,
    /*保存玩家移动之前的方块数据*/
    beforeMoveTiles: []
  },
  mutations: {
    /*加分方法*/
    awarded(state, value) {
      state.score += value || 0
    },
    /*得分重置*/
    resetScore(state) {
      state.score = 0
    },
    /**
     * 游戏状态改变
     * @param state
     */
    init(state) {
      state.winning = 0
    },
    win(state) {
      state.winning = 1
    },
    lose(state) {
      state.winning = 2
    },
    /**
     * 设置移动之前的方块数据
     */
    setBeforeMoveTiles(state, tiles) {
      state.beforeMoveTiles = tiles
    }
  },
  actions: {
  },
  modules: {
  }
})
